#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    int numberOfArrays(vector<int>& differences, int lower, int upper) {
        long long s = 0, min_s = 0, max_s = 0;
        for (auto& d : differences) {
            s += d;
            min_s = min(min_s, s);
            max_s = max(max_s, s);
        }
        return max(upper - lower - max_s + min_s + 1, 0LL);
    }
};